package org.ogv.usada.views;

import org.ogv.OGV;
import org.ogv.usada.models.GP;
import org.ogv.usada.models.Leaf;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Slice extends Sprite {
	
	private float _lifeTime;

	public Slice() {
		super(OGV.asset.getTextureRegion(GP.$().RES_TEXR_SLICE));
	}
	
	public void spawn(Leaf atLeaf) {
		setPosition(
			atLeaf.leafSprite.getX() + (atLeaf.leafSprite.getWidth() - getWidth())/2, 
			atLeaf.leafSprite.getY() + (atLeaf.leafSprite.getHeight() - getHeight())/2
		);
		setRotation(GP.$().RANDOM.nextFloat() * 360);
		_lifeTime = GP.$().GAME_SLICE_LIFETIME;
	}
	
	public void update(float delta) {
		if(_lifeTime > 0) {
			_lifeTime -= delta;
		}
	}
	
	@Override
	public void draw(SpriteBatch spriteBatch) {
		if(_lifeTime > 0)
			super.draw(spriteBatch);
	}
}
